package 面试真题;


import java.util.ArrayList;
import java.util.Scanner;

class Node {
    public int[] vales;
}

public class Ali201 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        int ans = 0;
        ArrayList<Node> nodes = new ArrayList<>();
        while (n-- > 0) {
            Node node = new Node();
            node.vales = new int[m];
            for (int i = 0; i < m; i++) {
                node.vales[i] = scanner.nextInt();
            }
            nodes.add(node);
        }
        for (int i = 0; i < nodes.size(); i++) {
            for (int j = i + 1; j < nodes.size(); j++) {
                boolean flag = true;
                int he = nodes.get(i).vales[0] + nodes.get(j).vales[0];
                for (int k = 1; k < m; k++) {
                    if (nodes.get(i).vales[k] + nodes.get(j).vales[k] != he) {
                        flag = false;
                        break;
                    }
                }
                if (flag) {
                    ans++;
                }
            }
        }
        System.out.print(ans);
    }
}

